package thread;

public class SyncDemo2 {
    public static void main(String[] args) {
        Shop shop = new Shop();
        Thread t2 = new Thread("张三"){
            public void run(){
                shop.buy();
            }
        };
        Thread t3 = new Thread("李四"){
            public void run(){
                shop.buy();
            }
        };
        t2.start();
        t3.start();
    }
}
class Shop {
    /*public synchronized void buy(){ */
    public void buy(){
        try {
            Thread t1 = Thread.currentThread();
            System.out.println(t1.getName()+"试衣服...");
            synchronized (this) {
                Thread.sleep(5000);
                System.out.println(t1.getName() + "换衣服...");
            }
            Thread.sleep(5000);
            System.out.println(t1.getName()+"结账离开");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}